﻿using UnityEngine;
using System.Collections;
using NhomTre_XocXoc;
public class PlayerController : MonoBehaviour {
	public static NguoiChoiXocDia nguoichoi;
	public string tenNgChoi;
	public static long soTien;
	private Nut[] nut;
	public GUIText tienNgChoi;
	public GUIText thangThua;
	public GUIText txttenNgChoi;
	int diem;
	// Use this for initialization
	void Start () {
		//nguoichoi.CuaDat = Button_DatCua.cuadat;
		soTien = long.Parse (Login.tien);
		nguoichoi  = new NguoiChoiXocDia(Login.ten,soTien);
		tienNgChoi.text = soTien.ToString();
		thangThua.text = "";
		txttenNgChoi.text = "Xin chao,"+Login.ten;
	}
	
	// Update is called once per frame
	void Update () {
	
			nguoichoi.CuaDat = Button_DatCua.cuadat;
			tienNgChoi.text= soTien.ToString();
			

		if (XocDiaController.modia) {
			CuaDat[] cuadat= Button_DatCua.cuadat;
			nut = XocDiaController.nut;
			diem = GameController.DiemNut (nut);

			for (int i = 0; i < cuadat.Length; i++) {
				Debug.Log(cuadat[i].Kieudat+"aaa"+cuadat[i].Tien_dat);
				if ((cuadat[i].Kieudat==0 && diem%2==0 && cuadat[i].Tien_dat>0) || (cuadat[i].Kieudat==1 && diem %2!=0 && cuadat[i].Tien_dat>0)) {
					soTien+=cuadat[i].Tien_dat*2;
				}
			Debug.Log(nguoichoi.Tong_so_tien.ToString());
			}

		}
		if (XocDiaController.baokq) {
			if (GameController.Thang (diem, nguoichoi.CuaDat)) {
				thangThua.color= Color.green;				
				thangThua.text = "Thang";
			} else
				{
					thangThua.color= Color.red;
									thangThua.text = "Thua";
				}
		} else
				thangThua.text = "";
		nguoichoi = new NguoiChoiXocDia (tenNgChoi, soTien);
	}


}

